import 'package:flutter/foundation.dart';

var globalTaskList = TaskList();

class TaskStats {
  TaskStats(this.total, this.completion);

  int total;
  int completion;
}

class Task {
  Task(this.id, this.name, this.stats);

  int id;
  String name;
  TaskStats stats;

  @override
  String toString() {
    return '{id: $id, name: $name:, stats:{total:${stats.total}, completion:${stats.completion}}}';
  }
}

class TaskList extends ChangeNotifier {
  TaskList()
      : tasks = [],
        count = 0;

  List<Task> tasks;
  int count;

  void add(task) {
    tasks.add(task);
    count++;
    notifyListeners();
  }

  void incrementCompletion(int taskId) {
    var task = tasks.singleWhere((e) => e.id == taskId);
    task.stats.completion++;
    notifyListeners();
  }
}
